import java.util.Scanner;


/**
 * 
 * @author Group 202
 * 
 * Exercise 4.1
 *
 */

public class Ableitung {

	public static void main(String[] args) 
	{
		Scanner scanner = new Scanner(System.in);
		StringBuilder builder = new StringBuilder();
		
		System.out.print("Anzahl der Koeffizienten: ");
		int countCoeff = scanner.nextInt();
		
		double[] polynom = new double[countCoeff];
		
		builder.append("Polynom: ");
		
		// Polynome einlesen und in dem ersten Double Array speichern.
		for (int i = 0; i < countCoeff; i++) 
		{
			System.out.print(String.format("Koeffizient fuer x^%s: ", i));
			polynom[i] = scanner.nextDouble();
			
			builder.append(polynom[i] > 0 ? "+" + polynom[i] : polynom[i]);
			builder.append("x^" + i + " ");
		}
		double[] derivationPolynom = new double[countCoeff];
		
		builder.append(System.getProperty("line.separator") + "Ableitung: ");
		
		// Ableitung errechnen und im zweiten Array speichern. Danach ausgeben.
		for (int i = 1; i < countCoeff; i++) 
		{
			derivationPolynom[i - 1] = polynom[i] * i;
			builder.append(derivationPolynom[i - 1] > 0 ? "+" + derivationPolynom[i - 1] : derivationPolynom[i - 1]);
			builder.append("x^" + (i - 1) + " ");
		}
		System.out.println(builder.toString());
	}
}
